home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / mcomm540.zip / SUPLMNT.DOC < prev    next >
Text File  |  1991-01-10  |  38KB  |  882 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.          ===============================================================
  7.  
  8.                           MCOMM SUPPLEMENTAL FUNCTIONS
  9.                   Mike Dumdei, 6 Holly Lane, Texarkana TX 75503
  10.  
  11.          ===============================================================
  12.  
  13.          The functions described in this document are non-async related
  14.          functions provided as part of the MCOMM library.  MCOMM is
  15.          first and foremost a serial I/O library, therefore, much more
  16.          effort went into describing the use of the async functions than
  17.          you will find here.  Also, because MCOMM is a serial library,
  18.          most of the supplemental functions are targeted towards commun-
  19.          ications programs.  The video functions correctly handle all
  20.          ANSI sequences commonly used by BBS systems.  They also support
  21.          windowed output, allowing you to limit the area of the screen
  22.          that will be written to.  For example, you can reserve the
  23.          bottom line of the screen for a status line and no writes, ANSI
  24.          clear screen commands, etc., will be allowed to overwrite or
  25.          erase it.
  26.  
  27.             ANSI sequences supported are:
  28.                CUP - cursor position
  29.                HVP - horizontal, vertical position
  30.                CUU - cursor up
  31.                CUD - cursor down
  32.                CUF - cursor forward
  33.                CUB - cursor backward
  34.                SCP - save cursor position
  35.                RCP - restore cursor position
  36.                ED  - erase display
  37.                EL  - erase line
  38.                SGR - set graphics rendition (colors)
  39.                FF  - form feed, not really ANSI, clears the screen
  40.  
  41.          Tabs, newlines, carriage returns, line feeds, backspace, the
  42.          bell character, etc. are supported also.  See the 'Global Video
  43.          Variables' section for information on options available for
  44.          handling control characters, scrolling, etc.
  45.  
  46.          In addition to the video routines, there are also timeout
  47.          functions, crc functions, string functions, a carrier watchdog
  48.          function, and several others.  On the following pages, the
  49.          video functions are listed first followed by the non-video type
  50.          functions.
  51.  
  52.          Distribution policy:
  53.             These functions are part of the MCOMM async library and may
  54.          not be distributed without the remaining MCOMM files.  No part
  55.          of the registered version may be distributed or used except as
  56.          stated in the license agreement.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.          GLOBAL VIDEO VARIABLES:
  64.  
  65.          v_seg - segment  address of video RAM, set by initvid()
  66.          v_mode - current video mode, set by initvid()
  67.          v_page - current video page, set by initvid()
  68.          v_color - attribute to use when displaying chars, this variable
  69.             is set directly by ANSI sequences that change the displayed
  70.             attribute and can be set from your C program to change the
  71.             current attribute (def = 7)
  72.          v_snow - snow flag, if 1 chars are written to screen during
  73.             vertical retrace, if 0 chars are written without waiting for
  74.             retrace
  75.          v_cga - a CGA video system was detected
  76.          v_bios - BIOS video flag, if 1 screen writes are performed
  77.             using BIOS INT 10, if 0 screen writes are done directly to
  78.             video RAM
  79.          v_wndsz - current window borders, set by SETWND macro
  80.             (def = 0,0,24,79)
  81.          v_btmrgt, v_rgt, v_btm, v_toplft, v_lft, v_top -
  82.             v_wndsz individual components
  83.          vs_wndsz - limits for d_msgat(), d_nchat(), & d_atrbat()
  84.          vs_btmrgt, vs_toplft  - vs_wndsz individual components
  85.          v_scrlm - scroll mode, if 1 then the window is scrolled when
  86.             the cursor would move off the bottom, if 0 the cursor wraps
  87.             back to the top  (def = 1)
  88.          v_cntrlm - control char handling, if 1 then control chars per-
  89.             form control functions, if 0 control chars are displayed as
  90.             graphic characters (def = 1)
  91.          v_textm - text mode, if 1 newlines are translated to CR/LF
  92.             pairs, if 0 newlines are displayed as LFs (def=1)
  93.          v_ansi - ansi mode, if 1 ANSI sequences are recognized, if 0
  94.             ANSI sequences are not recognized (def = 1)
  95.          v_wrel - if 1 cursor location arguments for functions that are
  96.             limited to the current window are relative to the top left
  97.             of the current window, if 0 cursor locations are absolute
  98.             (def = 0)
  99.          vs_wrel - if 1 cursor location arguments for functions that are
  100.             NOT limited to the current window are relative to the top
  101.             left of the current window, if 0 cursor locations are
  102.             absolute (def = 0)
  103.          v_ansiseq - shows that an ANSI sequence is currently in process
  104.             -- an ESC has been received by the display functions but the
  105.             terminating alpha character has not yet been received. (EX:
  106.             \33[0;36m is an ANSI sequence.  'v_ansiseq' is set to some
  107.             positive value when the ESC character is received and stay
  108.             positive until the sequence terminator is received.  When
  109.             the terminator is received, 'v_ansiseq' is set to a negative
  110.             value.  If the next character displayed after the terminator
  111.             is not the start of another ANSI sequence, 'v_ansiseq' is
  112.             reset to 0 after displaying that character.  This variable
  113.             is useful when stripping ANSI sequences from an incoming
  114.             stream of characters or when it is necessary to interrupt an
  115.             inprocess ANSI sequence.
  116.          v_bksp - if 1, backspace is destructive, if 0 backspace is not
  117.             destructive (def = 1)
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.          HANDLING OF UNSUPPORTED ANSI SEQUENCES:
  126.  
  127.          When an unsupported ANSI sequence is displayed, the ESC
  128.          character (a small back arrow), will be displayed followed by
  129.          the unrecognized terminating character.  The characters between
  130.          the ESC and unrecognized terminator are not displayed.
  131.  
  132.  
  133.          INTERRUPTING INPROCESS ANSI SEQUENCES:
  134.  
  135.          This section suggests some possible methods for handling the
  136.          situation where an ANSI sequence is in progress and it is nec-
  137.          essary to display characters that are not part of the sequence
  138.          and then resume the sequence.  An example of where this situa-
  139.          tion is a terminal program that is displaying incoming data
  140.          containing ANSI codes and the user of the program presses a key
  141.          that requires screen output in the middle of one of those
  142.          codes:
  143.                 Incoming data:    ESC[0;  (beginning of ANSI code)
  144.                 User keypress:     F1     (user wants a help screen)
  145.                 More incoming:    36m     (completion of ANSI code)
  146.  
  147.          The ANSI handler in the video library sees this:
  148.                   ESC[0;+----------------+
  149.                         |  Help Screen   |
  150.                         +----------------+36m
  151.          and since it doesn't know what to to with an ANSI code that
  152.          looks like that you see a small back arrow (for unrecognized
  153.          ANSI code), the help screen, and a 36m.
  154.  
  155.          To avoid this problem, you can do one of three things.  The
  156.          first is you can ignore the local user input until the
  157.          inprocess ANSI sequence is completed.  The v_ansiseq variable
  158.          described previously can be used to test whether or not an ANSI
  159.          sequence is currently in process.  Example:
  160.             if (KBHIT()) {
  161.                while (v_ansiseq && ((ch = rx_timeout(1)) != TIMED_OUT))
  162.                   d_ch(ch);
  163.                proc_keypress();
  164.             }
  165.  
  166.          The second method is to use the 'd_msgat' function to display
  167.          local strings.  It automatically save the ANSI sequence status,
  168.          and the present cursor position before displaying the passed
  169.          string.  On exit, the current status of any inprocess ANSI
  170.          sequences and the cursor position are restored.  It will also
  171.          place strings outside the current window making it the best
  172.          function for updating the terminal status line and displaying
  173.          local screens and messages.
  174.  
  175.          The last option is to manually preserve the v_ansiseq variable,
  176.          display local messages, and then manually restore v_ansiseq:
  177.             temp = v_ansiseq, v_ansiseq = 0;
  178.             displayhelp();
  179.             v_ansiseq = temp;
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.          VIDEO MACROS:
  187.  
  188.          ---------------------------------------------------------------
  189.          SETWND(top, left, btm, rgt)  -- Set Window Dimensions
  190.          ---------------------------------------------------------------
  191.          This macro is used to set the global variable that defines the
  192.          screen area that will be affected by the majority of the video
  193.          functions.  Initially set to 0,0,24,79.
  194.  
  195.  
  196.          ---------------------------------------------------------------
  197.          SETTOPLFT(top, lft), SETBTMRGT(btm, rgt)
  198.          ---------------------------------------------------------------
  199.          Same as above but only sets one corner.
  200.  
  201.  
  202.          ---------------------------------------------------------------
  203.          SETsWND(top, left, btm, rgt) -- Set Screen Dimensions
  204.          ---------------------------------------------------------------
  205.          Sets the screen limits for the functions that are allowed to
  206.          write outside the current window.
  207.  
  208.  
  209.          ---------------------------------------------------------------
  210.          SETsTOPLFT(top, lft), SETsBTMRGT(btm, rgt)
  211.          ---------------------------------------------------------------
  212.          Same as SETsWND but for one corner only.
  213.  
  214.  
  215.          ---------------------------------------------------------------
  216.          SCRBUF(rows, cols)
  217.          ---------------------------------------------------------------
  218.          Returns a value that is the required buffer size for the
  219.          pu_scrnd and fpu_scrnd functions.  It is used like this:
  220.  
  221.            sbuf = malloc(SCRBUF(25,80));
  222.            if (sbuf != NULL)
  223.               pu_scrnd(0, 0, 25, 80);
  224.  
  225.  
  226.          ---------------------------------------------------------------
  227.          d_strnat(row,col,char,attrib,count)
  228.          ---------------------------------------------------------------
  229.          Macro for compatibility with older versions of ANSIDRV.
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.          VIDEO FUNCTIONS:
  237.  
  238.          ---------------------------------------------------------------
  239.          initvid -- Initializes Video Variables
  240.          ---------------------------------------------------------------
  241.             int initvid(void);
  242.  
  243.          Initializes the global video variables, v_seg, v_mode, v_page,
  244.          and v_snow.  You MUST call this function before using any of
  245.          the other video functions.  Calling 'initvid' does not
  246.          automatically cause the linker to pull in the code for the
  247.          remaining ANSI video routines.  Initvid only includes the
  248.          global variables and enough code to initialize those variables.
  249.  
  250.  
  251.          ---------------------------------------------------------------
  252.          loc -- Locate the Cursor
  253.          ---------------------------------------------------------------
  254.             void loc(int row, int col);
  255.  
  256.          Locates the cursor at row, col.  The top left of the screen is
  257.          0,0.  If an attempt is made to locate the cursor outside the
  258.          current window the cursor is placed on the window edge closest
  259.          to the passed location.  Setting the global variable 'v_wrel'
  260.          to a non-zero value will make location 0,0 be the top, left
  261.          corner of the current window.
  262.  
  263.  
  264.          ---------------------------------------------------------------
  265.          d_strat -- Display String At Specified Location
  266.          ---------------------------------------------------------------
  267.             void d_strat(int row, int col, char *string);
  268.  
  269.          This function displays a string at row, col.  The attribute
  270.          used is the current value of the global variable 'v_color'.
  271.          The area where the string can be displayed is limited to the
  272.          current window (set by SETWND).
  273.  
  274.  
  275.          ---------------------------------------------------------------
  276.          d_str  -- Display String At Current Location
  277.          ---------------------------------------------------------------
  278.             void d_str(char *string);
  279.  
  280.          Displays a string at the current cursor position using v_color
  281.          for the attribute.
  282.  
  283.  
  284.          ---------------------------------------------------------------
  285.          d_chat -- Display Char At Specified Location
  286.          ---------------------------------------------------------------
  287.             void d_chat(int row, int col, char ch);
  288.  
  289.          Displays one character at the specified position using v_color
  290.          for the attribute.
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.          ---------------------------------------------------------------
  298.          d_ch -- Display Char at Current Location
  299.          ---------------------------------------------------------------
  300.             void d_ch(char ch);
  301.  
  302.          Display one character at the present cursor position using
  303.          v_color for the attribute.
  304.  
  305.  
  306.          ---------------------------------------------------------------
  307.          d_msgat -- Display Message At Location
  308.          ---------------------------------------------------------------
  309.             void d_msgat(int row, int col, int atrib, char *str);
  310.  
  311.          Displays string at the specified location using the specified
  312.          attribute.  This routine is not limited to writing within the
  313.          current window.  It is limited by the variable set by the
  314.          SETsWND macro (s stands for screen).  The routine does not move
  315.          the cursor and does not break up in process ANSI sequences.
  316.          Used to display strings outside the current window.
  317.  
  318.  
  319.          ---------------------------------------------------------------
  320.          d_msgatd -- Display Message At Location Direct Write
  321.          ---------------------------------------------------------------
  322.             void d_msgatd(int row, int col, int atrib, char *str);
  323.  
  324.          This routine writes 'str' at the specified location using the
  325.          given attribute.  Unlike the previous function, this function
  326.          does not support ANSI or control characters.  It is for
  327.          displaying strings on the screen in the fastest possible
  328.          manner.  The 'v_bios' variable described in the list of global
  329.          variables does not apply to this function.  It always uses
  330.          direct screen writes.
  331.  
  332.  
  333.          ---------------------------------------------------------------
  334.          d_atrbat -- Display Attribute At Location With Count
  335.          ---------------------------------------------------------------
  336.             void d_atrbat(int row, int col, int atrb, int count);
  337.  
  338.          Resets the displayed attribute at the specified location to the
  339.          given attribute for the given number of locations.  This rout-
  340.          ine performs like d_msgat() in regard to window limitations,
  341.          cursor movement, and ANSI sequences.
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.          ---------------------------------------------------------------
  349.          d_nchat -- Display Char At Location With Count
  350.          ---------------------------------------------------------------
  351.             void d_nchat(char row, char col, char ch, char atrb,
  352.              int nbr, char dir);
  353.  
  354.          Displays 'ch', 'nbr' times, using 'atrb' for the attribute, at
  355.          'row, col'.  If 'dir' is 0 the chars are displayed vertically
  356.          otherwise they are displayed horizontally.  This routine
  357.          performs like d_msgat in regard to window limitations, cursor
  358.          movement, and ANSI sequences.
  359.  
  360.  
  361.          ---------------------------------------------------------------
  362.          pu_scrnd -- Move Specified Screen Region To A Buffer
  363.          ---------------------------------------------------------------
  364.             void pu_scrnd(int row, int col, int nrows, int ncols,
  365.              char *buf);
  366.  
  367.          This function saves a section of the video display beginning at
  368.          'row', 'col', that is 'nrows' high and 'ncols' wide.  It also
  369.          saves the current cursor position and shape.  The buffer to
  370.          hold the screen information must be (2 * nrows * ncols) + 16
  371.          bytes in size.  The 'v_bios' variable does not apply to this
  372.          function.  It operates in direct write mode only.
  373.  
  374.  
  375.          ---------------------------------------------------------------
  376.          po_scrnd -- Restore a Screen Saved by 'pu_scrnd' Function
  377.          ---------------------------------------------------------------
  378.             void po_scrnd(char *buf);
  379.  
  380.          Restores the screen and cursor information that was placed in
  381.          'buf' by a previous pu_scrnd call.  The 'v_bios' function does
  382.          not apply to this function.
  383.  
  384.  
  385.          ---------------------------------------------------------------
  386.          fpu_scrnd -- Move Specified Screen Region To A FAR Buffer
  387.          ---------------------------------------------------------------
  388.             void fpu_scrnd(int row, int col, int nrows, int ncols,
  389.              char _far *buf);
  390.  
  391.          Same as pu_scrnd except moves screen information to a FAR
  392.          buffer.
  393.  
  394.          ---------------------------------------------------------------
  395.          fpo_scrnd -- Restore a Screen Saved by 'fpu_scrnd' Function
  396.          ---------------------------------------------------------------
  397.             void fpo_scrnd(char _far *buf);
  398.  
  399.          Same as po_scrnd except restores data pushed by 'fpo_scrnd'.
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.          ---------------------------------------------------------------
  407.          pushscrn -- Move Specified Screen Region To A Buffer      ( C )
  408.          ---------------------------------------------------------------
  409.             int pushscrn(int row, int col, int nrows, int ncols);
  410.  
  411.          C function that utilizes pu_scrnd and malloc to build a last in
  412.          first out stack of up to 10 screens.  Performs the same as
  413.          pu_scrnd except automatically allocates the buffer space.
  414.          C source code is included for this function.  Returns 0 if
  415.          successful, non-zero if an attempt is made to push too many
  416.          screens or the call to malloc space for the screen data fails.
  417.  
  418.  
  419.          ---------------------------------------------------------------
  420.          popscrn -- Restore Last Screen Saved by 'pushscrn'        ( C )
  421.          ---------------------------------------------------------------
  422.             int popscrn(void);
  423.  
  424.          Restores last screen pushed by pushscrn function.  Returns 0 if
  425.          successful or non-zero if an attempt is made to pop a screen
  426.          when no more screens remain in the screen stack.
  427.  
  428.  
  429.          ---------------------------------------------------------------
  430.          fpushscrn -- Move Specified Screen Region To FAR Buffer   ( C )
  431.          ---------------------------------------------------------------
  432.             int fpushscrn(int row, int col, int nrows, int ncols);
  433.  
  434.          Same as pushscrn except the screen buffers are allocated from
  435.          far memory using your compiler's version of a far malloc
  436.          function.  (MSC _fmalloc, Turbo C = farmalloc).  Source code is
  437.          included if you are using a compiler that has a different name
  438.          for the function to do this.
  439.  
  440.  
  441.          ---------------------------------------------------------------
  442.          fpopscrn -- Restore Last Screen Saved by 'fpushscrn'      ( C )
  443.          ---------------------------------------------------------------
  444.             int fpopscrn(void);
  445.  
  446.          Same as popscrn except restores last screen pushed by
  447.          fpushscrn.
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.          ---------------------------------------------------------------
  455.          moveblk -- Move Screen To Buffer / Buffer To Screen
  456.          ---------------------------------------------------------------
  457.             void moveblk(int row, int col, int nrows, int ncols,
  458.              char *buf, int dirflag);
  459.  
  460.          This function does the same thing as pu_scrnd and po_scrnd
  461.          combined except it does not save data on the cursor position or
  462.          shape and all args are needed when both saving and restoring.
  463.          The 'dirflag' determines which direction the data is to be
  464.          moved.  If it is NZ, data is transferred from the screen to the
  465.          buffer.  If it is zero, then buffer data is transferred to the
  466.          screen.  The additional 16 bytes of buffer space required by
  467.          pu_scrnd are not required for this function since it does not
  468.          build the header for the screen region and cursor data.
  469.  
  470.  
  471.          ---------------------------------------------------------------
  472.          rd_scrn -- Read Attrib/Char At Cursor Position
  473.          ---------------------------------------------------------------
  474.             int rd_scrn(void);
  475.  
  476.          Reads the attribute and character at the current cursor pos-
  477.          ition.  The attribute is returned in the upper 8 bits of the
  478.          return value and the character in the lower 8 bits.
  479.  
  480.  
  481.          ---------------------------------------------------------------
  482.          rd_scrnd -- Read Screen String From Specified Location
  483.          ---------------------------------------------------------------
  484.             char *rd_scrnd(int row, int col, int nbytes, char *buf);
  485.  
  486.          Reads a string that is a maximum of 'nbytes' long beginning at
  487.          the specified location.  The string is stored in 'buf' and
  488.          trailing spaces are trimmed.  The 'v_bios' variable does not
  489.          apply to this function.  The return value is a pointer to
  490.          'buf'.
  491.  
  492.          ---------------------------------------------------------------
  493.          cls -- Clear Currently Defined Window
  494.          ---------------------------------------------------------------
  495.             void  cls(void);
  496.  
  497.          Clears the current window using v_color for the attribute.  Re-
  498.          turns nothing.
  499.  
  500.  
  501.          ---------------------------------------------------------------
  502.          scrlup -- Scroll Window Up
  503.          ---------------------------------------------------------------
  504.             void scrlup(int nbrlines);
  505.  
  506.          Scrolls the current window up the specified number of lines.
  507.          The attribute used for blank lines is 'v_color'.
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.          ---------------------------------------------------------------
  515.          scrldn -- Scroll Window Down
  516.          ---------------------------------------------------------------
  517.             void scrldn(int nbrlines);
  518.          Same as previous function except scrolls down.
  519.  
  520.  
  521.          ---------------------------------------------------------------
  522.          scrlupat -- Scroll Specified Area Up
  523.          ---------------------------------------------------------------
  524.             void scrlup(int top, int lft, int btm, int rgt, int nlines);
  525.  
  526.          Same as previous scrlup function except instead of using the
  527.          current window, it scrolls the specified area.
  528.  
  529.  
  530.          ---------------------------------------------------------------
  531.          scrldnat -- Scroll Specified Area Down
  532.          ---------------------------------------------------------------
  533.             void scrldn(int nbrlines);
  534.          Same as previous scrldn function except instead of using the
  535.          current window, it scrolls the specified area.
  536.  
  537.  
  538.          ---------------------------------------------------------------
  539.          setcurloc -- Set Cursor Location
  540.          ---------------------------------------------------------------
  541.             void setcurloc(int location);
  542.  
  543.          Similar to loc(), but this function passes the row and column
  544.          one variable with the upper 8 bits being the row and the lower
  545.          8 bits the column.  This function is used in conjunction with
  546.          getcurloc() to save and restore the cursor position.
  547.  
  548.  
  549.          ---------------------------------------------------------------
  550.          getcurloc -- Get Cursor Location
  551.          ---------------------------------------------------------------
  552.             int getcurloc(void);
  553.  
  554.          Returns the cursor location as an integer.  The upper 8 bits is
  555.          the row, and the lower 8 bits is the column.
  556.  
  557.  
  558.          ---------------------------------------------------------------
  559.          setcursiz -- Set Cursor Size
  560.          ---------------------------------------------------------------
  561.             void setcursiz(int);
  562.  
  563.          Sets the starting and ending scan lines for the cursor. The
  564.          upper 8 bits are the starting scan line and the lower 8 bits
  565.          are the ending scan line.
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.          ---------------------------------------------------------------
  573.          getcursiz -- Get Cursor Size
  574.          ---------------------------------------------------------------
  575.             int getcursiz(void);
  576.  
  577.          Returns the current starting and ending scan lines of the cur-
  578.          sor.  The high bits are the starting scan line and the lower 8
  579.          bits are the ending scan line.
  580.  
  581.  
  582.          ---------------------------------------------------------------
  583.          setvmode -- Set Video Mode
  584.          ---------------------------------------------------------------
  585.             void setvmode(int mode);
  586.  
  587.          Sets the video mode to 'mode'.  The only modes that these func-
  588.          tions will work in, however, are the 80 x 25 text modes.
  589.  
  590.  
  591.          ---------------------------------------------------------------
  592.          getvmode -- Get Video Mode
  593.          ---------------------------------------------------------------
  594.             int getvmode(void);
  595.  
  596.          Returns the current video mode.
  597.  
  598.  
  599.          ---------------------------------------------------------------
  600.          setvpage -- Set Video Page
  601.          ---------------------------------------------------------------
  602.             void setvpage(int page);
  603.  
  604.          Sets the video page to 'page'.  Pages are only supported on
  605.          color systems.  This function also modifies v_seg so that it
  606.          reflects the new page value set.
  607.  
  608.  
  609.          ---------------------------------------------------------------
  610.          getvpage -- Get Video Page
  611.          ---------------------------------------------------------------
  612.             int getvpage(void);
  613.  
  614.          Returns the current video page.
  615.  
  616.  
  617.          ---------------------------------------------------------------
  618.          setvbordr -- Set Video Border
  619.          ---------------------------------------------------------------
  620.             void setvbordr(int attrib);
  621.  
  622.          Sets the border color of the screen.
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.          MISCELLANEOUS FUNCTIONS:
  630.  
  631.          ---------------------------------------------------------------
  632.          str*just -- right, left, or center justify a string.
  633.          ---------------------------------------------------------------
  634.          These functions 1st trim all spaces (ASCII 32's) and then just-
  635.          ify the string in the specified field width using the specified
  636.          pad character.  The memory area where the string is located
  637.          must be at least field size + 1 in size.  If the string is
  638.          longer than the field width, strljust and strcentr truncate the
  639.          right portion of the string; strrjust will cut off the right
  640.          side.  Only ASCII 32's are trimmed.
  641.  
  642.          Returns a pointer to the justified string.
  643.  
  644.          char *strrjust(char *, int, char);
  645.          char *strljust(char *, int, char);
  646.          char *strcentr(char *, int, char);
  647.  
  648.          str_out = strrjust(str_in, fieldsz, padchar);
  649.  
  650.  
  651.          ---------------------------------------------------------------
  652.          str*trim -- trims spaces (ASCII 32's only) from a string.
  653.          ---------------------------------------------------------------
  654.          Trims spaces from left, right, or both ends of a string.
  655.  
  656.          Returns pointer to the passed string.
  657.  
  658.          char *strrtrim(char *);
  659.          char *strltrim(char *);
  660.          char *strtrim(char *);
  661.  
  662.          str_out = strrtrim(str_in);
  663.  
  664.  
  665.          ---------------------------------------------------------------
  666.          strsum -- strcat for multiple strings.
  667.          ---------------------------------------------------------------
  668.          Makes one string from multiple strings.  Unlike strcat, the
  669.          first string in the list is not one of the strings to add but
  670.          instead is a buffer for the result of adding the rest of the
  671.          strings in the list.  The args to the function are:
  672.             the dest, a variable number of char *'s, a NULL ptr
  673.  
  674.          Returns a pointer to the result string.
  675.  
  676.          char *strsum(char *, ...);
  677.  
  678.          str_out = strsum(str_out, str_in1, str_in2, ..., NULL);
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.          ---------------------------------------------------------------
  686.          strpbrkf -- finds 1st char in str1 not in str2.
  687.          ---------------------------------------------------------------
  688.          This function looks for the first character in 'str1' that does
  689.          not belong to the character set contained in 'str2' and returns
  690.          a pointer to that character.  If 'str1' consists entirely of
  691.          characters in 'str2', NULL is returned.  Opposite of strpbrk.
  692.  
  693.          char *strpbrkf(char *, char *);
  694.          rtnstr = strpbrkf(str1, str2);
  695.  
  696.  
  697.          ---------------------------------------------------------------
  698.          strrstr -- find last occurrence of str2 in str1.
  699.          ---------------------------------------------------------------
  700.          This function returns a pointer to the last occurrence of
  701.          'str2' within 'str1'.  If 'str2' is not in 'str1', NULL is
  702.          returned.  This is identical to the standard 'strstr' function
  703.          except it works from the end of 'str1' towards the beginning
  704.          instead of the other way.
  705.  
  706.          char *strrstr(char *, char *);
  707.          rtnstr = strrstr(str1, str2);
  708.  
  709.  
  710.          ---------------------------------------------------------------
  711.          strcntch -- returns number occurrences of char in string.
  712.          ---------------------------------------------------------------
  713.          int strcntchr(char *, char);
  714.          count = strcntchr(string, srchchar);
  715.  
  716.  
  717.          ---------------------------------------------------------------
  718.          calc_crc -- 16 bit CRC routine for block data.
  719.          ---------------------------------------------------------------
  720.          Calculates the CRC for a block of data 'count' bytes long.
  721.          Returns CRC.
  722.  
  723.          int calc_crc(char *, int);
  724.          crc = calc_crc(data, nbr_bytes_of_data);
  725.  
  726.  
  727.          ---------------------------------------------------------------
  728.          update_crc -- 16 bit CRC for character at a time data.
  729.          ---------------------------------------------------------------
  730.          Returns updated CRC.
  731.  
  732.          int update_crc(int, char);
  733.          crc = update_crc(crc, char);
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.          ---------------------------------------------------------------
  741.          watchdogset -- Enables/Disables watchdog function  (C function)
  742.          watchdoghook -- ASM function used by WATCHDOG.C
  743.          ---------------------------------------------------------------
  744.          int watchdogset(int flag, int combase)
  745.  
  746.          To enable:  call with flag = 1
  747.             combase = base adrs of comm chip (ex: 3F8)
  748.          To disable: call with flag = 0
  749.             combase = don't care
  750.  
  751.          This function monitors Carrier Detect on the selected serial
  752.          port and does a cold reboot if the carrier is lost.  If you use
  753.          both this function and the TIMEOUT functions make sure you
  754.          uninstall the hooks in the reverse order that you installed
  755.          them and make sure that you uninstall them before you exit your
  756.          program.  Failing to do this will cause your system to crash
  757.          (the redirected interrupt vectors are now pointing to freed
  758.          memory instead of a program).
  759.  
  760.  
  761.          ---------------------------------------------------------------
  762.          ctshookset -- Patch to BIOS INT14 to prevent timeouts when
  763.             using CTS handshaking  (C function)
  764.          int14ctshook -- ASM function used with CTSHOOKSET
  765.          ---------------------------------------------------------------
  766.          int ctshookset(int flag, int portval, int combase)
  767.          void interrupt far int14ctshook(void);
  768.  
  769.          To enable:  call with flag = 1
  770.             portval = COM1 (0) or COM2 (1)
  771.             combase = base adrs of comm chip (ex: 3F8)
  772.          To disable: call with flag = 0
  773.             portval = don't care
  774.             combase = don't care
  775.  
  776.          This function sets a hook into the BIOS serial interrupt vector
  777.          that waits indefinitely for CTS to go high on the specified
  778.          port when sending data.  All INT14 calls that are not for the
  779.          specified port and all service requests except for 'send byte'
  780.          are passed on to the old INT14 vector unaltered.  In other
  781.          words for the hook to have any effect when INT14 is called:
  782.             1)  DX has to equal the 'portval' you set here
  783.             2)  AH has to equal '1' -- the send char service ID
  784.          The effect it has then is to wait for CTS to be true then exe-
  785.          cute the old INT14 interrupt.  The purpose of the function is
  786.          keep high speed modems that CTS handshake from creating timeout
  787.          errors when redirecting stdout and stderr to the comm port.  Be
  788.          SURE to uninstall the hook before exiting your program or the
  789.          redirected interrupt vector will be pointing to free memory
  790.          instead of an interrupt handler.
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.          ---------------------------------------------------------------
  798.          tickhookset -- Enables/Disables 'ticker' for timer functions
  799.          ---------------------------------------------------------------
  800.          int tickhookset(int flag)
  801.  
  802.          To enable:  call with flag = 1
  803.          To disable: call with flag = 0
  804.  
  805.          This function enables the 'tick counter' used by the timeout
  806.          and tdelay functions by pointing the TIMER interrupt vector,
  807.          1Ch, to a new interrupt handler that increments the counter
  808.          approximately 18.2 times per second.  The advantage of using
  809.          this method over the BIOS function is no coding is needed to
  810.          account for the possibility of calling your timer functions
  811.          near midnight.  The 'tick counter' is a long and may be read by
  812.          calling 'get_ticker'.
  813.  
  814.          YOU MUST DISABLE 'TICKER' BEFORE EXITING YOUR PROGRAM.
  815.  
  816.  
  817.          ---------------------------------------------------------------
  818.          set_timeout     -- initializes a timer
  819.          set_longtimeout -- initialize a long timer
  820.          timed_out       -- checks if a timeout has occurred
  821.          ---------------------------------------------------------------
  822.          void set_timeout(long *t_out, unsigned ticks);
  823.  
  824.          int timed_out(long *t_out);
  825.  
  826.          These functions work in conjunction with each other and require
  827.          the 'tick counter' to be activated by TICKHOOKSET.  The fol-
  828.          lowing macros are defined in EXTRA.H:
  829.             SET_TO_TENTHS(to, tenths)  set_timeout((&to), (tenths)*9/5)
  830.             SET_TO_SECS(to, secs)      set_timeout((&to), (secs)*18)
  831.             SET_TO_MINS(to, mins)      set_timeout((&to), (mins)*1080)
  832.          After setting the timeout value with one of the above macros
  833.          you then call timed_out() see if a timeout has occurred.  Here
  834.          is an example:
  835.  
  836.             long to;
  837.             int toolong = 0;
  838.  
  839.             tickhookset(1);                      /* enable hook */
  840.             SET_TO_SECS(to, 2);       /* set timeout for 2 secs */
  841.             while (!(toolong = timed_out(&to)))
  842.             {
  843.                if (condition_met()) /* wait for cond 2 secs max */
  844.                   break;
  845.             }
  846.             if (toolong)             /* timed out if toolong NZ */
  847.                return TIMEOUT_ERR;
  848.  
  849.          Notice that the macro does not require the '&' operator but the
  850.          call to timed_out() does.  Using these functions, you may have
  851.          as many timeouts going as you have timeout variables.
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.          ---------------------------------------------------------------
  859.          get_ticker -- get the current value of internal tick counter
  860.          ---------------------------------------------------------------
  861.          long get_ticker(void);
  862.  
  863.          Returns the value of the internal tick counter.  This counter
  864.          is incremented 18.2 times a second from the time tickhookset(1)
  865.          is called until tickhookset(0) is called.
  866.  
  867.  
  868.          ---------------------------------------------------------------
  869.          tdelay -- kill time function
  870.          ---------------------------------------------------------------
  871.          int tdelay(unsigned ticks);
  872.  
  873.          This functions delays the specified number of ticks and then
  874.          returns.  Before using this function you must enable the
  875.          internal tick counter by calling 'tickhookset'.
  876.  
  877.          The following macros are defined in EXTRA.H:
  878.             DELAY_TENTHS(tenths)     tdelay(((tenths)*9/5)+1)
  879.             DELAY_SECS(secs)         tdelay((secs)*18)
  880.             DELAY_MINS(mins)         tdelay((mins)*1080)
  881.  
  882.